//
//  CNoticeView.m
//  HCHK_iphone
//
//  Created by yilong zhang on 11-12-21.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "CNoticeView.h"

@implementation CNoticeView

@synthesize m_BgView;
@synthesize m_Titlelb;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) 
    {
        // Initialization code
        self.clipsToBounds = YES;
        
        m_BgView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, frame.size.width-10, frame.size.height-10)];
        //m_BgView.image = image;
        m_BgView.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
        m_BgView.layer.borderWidth = 1;
        m_BgView.layer.borderColor = [[UIColor darkGrayColor] CGColor];
        m_BgView.layer.cornerRadius= 5;
        m_BgView.layer.shadowColor = [[UIColor blackColor] CGColor];
        m_BgView.layer.shadowOffset = CGSizeMake(4, 4);
        m_BgView.layer.shadowRadius = 1;
        m_BgView.layer.shadowOpacity = 0.7;
        [self addSubview:m_BgView];
        [m_BgView release];
        
        UIFont *font = [UIFont fontWithName:@"Helvetica" size:14];
        m_Titlelb = [[UILabel alloc] initWithFrame:m_BgView.frame];
        m_Titlelb.backgroundColor = [UIColor clearColor];
        m_Titlelb.textAlignment = UITextAlignmentCenter;
        m_Titlelb.textColor = [UIColor blackColor];
        m_Titlelb.font = font;
        [self addSubview:m_Titlelb];
        [m_Titlelb release];
        
        self.backgroundColor = [UIColor clearColor];
        self.alpha = 0.0;
    }
    return self;
}

-(void)SetNoticeContent:(NSString*)content
{
    m_Titlelb.text = content;
}

-(void)Show:(NSString*)title
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(DidShow)];
    self.alpha = 1.0;
    m_Titlelb.text = title;
    [UIView commitAnimations];
}

-(void)DidShow
{
    [self performSelector:@selector(Hidden) withObject:self afterDelay:1.5];
}

-(void)Hidden
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(DidHidden)];
    self.alpha = 0.0;
    [UIView commitAnimations];
}

-(void)DidHidden
{
    [self removeFromSuperview];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
